package com.youhome.service.service.impl;


import com.youhome.common.exception.CustomException;
import com.youhome.common.response.Result;
import com.youhome.common.response.ResultCode;
import com.youhome.service.mapper.ReportSearchUndoneMapper;
import com.youhome.service.model.ReportSearchUndone;
import com.youhome.service.service.ReportSearchUndoneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * Created by chen365 on 2017/9/11.
 */
@Service
public class ReportSearchUndoneServiceImpl implements ReportSearchUndoneService {
    @Autowired
    private ReportSearchUndoneMapper reportSearchUndoneMapper;

    @Override
    public int insertSelective(ReportSearchUndone record) throws Exception {
        record.setCreateTime(new Date());
        return reportSearchUndoneMapper.insertSelective(record);
    }

    @Override
    public int selectCountByBean(ReportSearchUndone reportSearchUndone) {
        return reportSearchUndoneMapper.selectCountByBean(reportSearchUndone);
    }

    @Override
    public void searchUndone(ReportSearchUndone reportSearchUndone) throws CustomException {
        if (reportSearchUndoneMapper.selectCountByBean(reportSearchUndone) > 0) {
            throw new CustomException(ResultCode.ERROR_RESUBMIT);
        }
        if (reportSearchUndoneMapper.insertSelective(reportSearchUndone) == 0) {
            throw new CustomException(ResultCode.FAIL);
        }
    }
}
